home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / misc / emu / ATUtilities.lha / ATUtilities / talk.c < prev    next >
C/C++ Source or Header  |  2000-09-26  |  9KB  |  290 lines

  1. /* ******************************************************************* */
  2. /* **                                                               ** */
  3. /* **                     ATKeyboard Version 4.0                    ** */
  4. /* **            Copright (C) 1992-1994 by Thomas Dreibholz         ** */
  5. /* **                      All rights reserved                      ** */
  6. /* **                                                               ** */
  7. /* **                         Sprachausgabe                         ** */
  8. /* **                                                               ** */
  9. /* ******************************************************************* */
  10.  
  11. #include "ATKeyboard.h"
  12.  
  13. EXTERN BOOL                  Speak;
  14. EXTERN UBYTE                *TitelText;
  15. extern struct Menu           Menu1;
  16. extern struct TextAttr       OpalFontDef;
  17. extern struct Einstellungen  Einstellungen;
  18. extern struct Window        *WindowPtr;
  19.  
  20. UBYTE  Channels[]={3,5,10,12};
  21. UBYTE *TestText="A-T-Keyboard Narrator Device Test";
  22.  
  23. UBYTE              *SpeakBuffer;
  24. LONG                NarratorDev=-1L;
  25. struct narrator_rb *NarratorReq;
  26. struct MsgPort     *NarratorPort;
  27.  
  28. LONG Div0();
  29.  
  30.  
  31. /* Text sprechen */
  32. VOID Say(text)
  33.  UBYTE *text;
  34. {
  35.  LONG error;
  36.  
  37.  if(NarratorDev==-1) return;
  38.  if(Speak==FALSE) return;
  39.  
  40.  error=Translate(text,strlen(text),SpeakBuffer,1024);
  41.  if(error==0)
  42.   {
  43.    NarratorReq->rate=Einstellungen.SpeakRate;
  44.    NarratorReq->pitch=Einstellungen.SpeakPitch;
  45.    NarratorReq->mode=Einstellungen.SpeakMode;
  46.    NarratorReq->sex=Einstellungen.SpeakSex;
  47.    NarratorReq->ch_masks=&Channels;
  48.    NarratorReq->nm_masks=4;
  49.    NarratorReq->volume=Einstellungen.SpeakVolume;
  50.    NarratorReq->sampfreq=Einstellungen.SpeakFreq;
  51.    NarratorReq->mouths=0;
  52.    NarratorReq->message.io_Command=CMD_WRITE;
  53.    NarratorReq->message.io_Data=SpeakBuffer;
  54.    NarratorReq->message.io_Length=strlen(SpeakBuffer);
  55.    DoIO(NarratorReq);
  56.   }
  57. }
  58.  
  59. /* Narrator installieren */
  60. BOOL InitNarrator()
  61. {
  62.  SpeakBuffer=AllocMem(1024,MEMF_CLEAR|MEMF_PUBLIC);
  63.  if(SpeakBuffer==NULL) return(FALSE);
  64.  NarratorPort=CreatePort("ATKeyboard Narrator Port",0);
  65.  if(NarratorPort==NULL) return(FALSE);
  66.  NarratorReq=CreateExtIO(NarratorPort,sizeof(struct narrator_rb));
  67.  if(NarratorReq==NULL) return(FALSE);
  68.  NarratorDev=OpenDevice("narrator.device",0,NarratorReq,0);
  69.  if(NarratorDev!=0) return(FALSE);
  70.  return(TRUE);
  71. }
  72.  
  73. /* Narrator entfernen */
  74. VOID RemoveNarrator()
  75. {
  76.  if(NarratorDev==0)
  77.   {
  78.    Say("have a nice day");
  79.    if( (CheckIO(NarratorReq)) != NULL) WaitIO(NarratorReq);
  80.    CloseDevice(NarratorReq);
  81.   }
  82.  if(NarratorReq) DeleteExtIO(NarratorReq);
  83.  if(NarratorPort) DeletePort(NarratorPort);
  84.  if(SpeakBuffer) FreeMem(SpeakBuffer,1024);
  85. }
  86.  
  87. UWORD oldw=0xFFFF,oldh,oldww,oldwh;
  88.  
  89. VOID DrawMouth(win,w,h)
  90.  struct Window   *win;
  91.  UWORD            w,h;
  92. {
  93.  REGISTER UWORD            ww,wh;
  94.  register struct RastPort *rp;
  95.  
  96.  rp=win->RPort;
  97.  
  98.  if(oldw!=0xFFFF)
  99.   {
  100.    SetAPen(rp,0);
  101.    Move(rp,oldww-oldw,oldwh);
  102.    Draw(rp,oldww,oldwh-oldh);
  103.    Draw(rp,oldww+oldw,oldwh);
  104.    Draw(rp,oldww,oldwh+oldh);
  105.    Draw(rp,oldww-oldw,oldwh);
  106.   }
  107.  
  108.  ww=(win->Width/2)-10;
  109.  wh=(win->Height/2)-10;
  110.  
  111.  w*=ww/16;
  112.  h*=wh/16;
  113.  
  114.  SetAPen(rp,3);
  115.  WaitTOF();
  116.  Move(rp,ww-w,wh);
  117.  Draw(rp,ww,wh-h);
  118.  Draw(rp,ww+w,wh);
  119.  Draw(rp,ww,wh+h);
  120.  Draw(rp,ww-w,wh);
  121.  
  122.  oldw=w;
  123.  oldh=h;
  124.  oldww=ww;
  125.  oldwh=wh;
  126. }
  127.  
  128. /* Narrator-Einstellungen */
  129. VOID NarratorPrefs()
  130. {
  131.  UBYTE                        *Titel,error,*teststr;
  132.  BOOL                          ende;
  133.  ULONG                         Class;
  134.  register struct Gadget       *female,*robot,*gad,*freq,*rate,*pitch,*vol;
  135.  register struct Window       *win,*mwin;
  136.  struct RastPort              *rp,*mrp;
  137.  register struct IntuiMessage *msg;
  138.  register struct PropInfo     *pi;
  139.  struct mouth_rb              *io;
  140.  struct MsgPort               *port;
  141.  
  142.  ClearMenuStrip(WindowPtr);
  143.  Titel=WindowPtr->Title;
  144.  SetWindowTitles(WindowPtr,TitelText,TitelText);
  145.  
  146.  win=CreateStdWindow("ATKeyboard - Sprachausgabeeinstellungen",
  147.                      10,10,450,112,
  148.                      CLOSEWINDOW|GADGETUP,
  149.                      ACTIVATE|WINDOWDEPTH|WINDOWDRAG|WINDOWCLOSE);
  150.  if(win!=NULL)
  151.   {
  152.    rp=win->RPort;
  153.    SetFont(rp,GetOpalFont());
  154.    SelectStdFPen(rp);
  155.    WriteText(rp,15,25,"Frequenz:");
  156.    freq=CreatePropGadget(win,150,15,280,12,Div0(65535*(Einstellungen.SpeakFreq-5000),23000),0,65535/23000,0,1);
  157.    WriteText(rp,15,40,"Worte/Sek:");
  158.    rate=CreatePropGadget(win,150,30,280,12,Div0(65535*(Einstellungen.SpeakRate-40),360),0,65535/360,0,2);
  159.    WriteText(rp,15,55,"Grundtonhöhe:");
  160.    pitch=CreatePropGadget(win,150,45,280,12,Div0(65535*(Einstellungen.SpeakPitch-65),255),0,65535/255,0,3);
  161.    WriteText(rp,15,70,"Lautstärke:");
  162.    vol=CreatePropGadget(win,150,60,280,12,Div0(65535*Einstellungen.SpeakVolume,64),0,65535/64,0,30);
  163.    if(Einstellungen.SpeakSex==1)
  164.      female=CreateSToggleGadget(win,15,75,180,12,"weibliche Stimme",4);
  165.    else
  166.      female=CreateNToggleGadget(win,15,75,180,12,"weibliche Stimme",4);
  167.    if(Einstellungen.SpeakMode==1)
  168.      robot=CreateSToggleGadget(win,250,75,180,12,"roboterhafte Stimme",5);
  169.    else
  170.      robot=CreateNToggleGadget(win,250,75,180,12,"roboterhafte Stimme",5);
  171.    CreateBoolGadget(win,15,90,50,12,"Test",10);
  172.    teststr=CreateStringGadget(win,70,90,360,12,TestText,256,11);
  173.  
  174.    port=CreatePort("ATKeyboard Narrator Mouthshape Port",0);
  175.    if(port!=NULL)
  176.     {
  177.      io=CreateExtIO(port,sizeof(struct mouth_rb));
  178.      if(io!=NULL)
  179.       {
  180.        io->voice.message.io_Device=NarratorReq->message.io_Device;
  181.        io->voice.message.io_Unit=NarratorReq->message.io_Unit;
  182.        io->voice.message.io_Unit->unit_flags=NarratorReq->message.io_Unit->unit_flags;
  183.        mwin=CreateStdWindow("Test",445,110,190,95,
  184.                             0,
  185.                             WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING|SMART_REFRESH|GIMMEZEROZERO);
  186.        if(mwin!=NULL)
  187.         {
  188.          mwin->MinWidth=50;
  189.          mwin->MinHeight=30;
  190.          mwin->MaxWidth=640;
  191.          mwin->MaxHeight=256;
  192.          mrp=mwin->RPort;
  193.          SetAPen(mrp,3);
  194.          DrawMouth(mwin,10,0);
  195.         }
  196.       }
  197.     }
  198.    rp=win->RPort;
  199.    ende=FALSE;
  200.    while(ende==FALSE)
  201.     {
  202.      WaitPort(win->UserPort);
  203.      msg=GetMsg(win->UserPort);
  204.      Class=msg->Class;
  205.      gad=msg->IAddress;
  206.      ReplyMsg(msg);
  207.      switch(Class)
  208.       {
  209.        case GADGETUP:
  210.          pi=freq->SpecialInfo;
  211.          Einstellungen.SpeakFreq=(UWORD)Div0(pi->HorizPot*23000L,65535L)+(UWORD)5000;
  212.          pi=pitch->SpecialInfo;
  213.          Einstellungen.SpeakPitch=(UWORD)Div0(pi->HorizPot*255L,65535L)+(UWORD)65;
  214.          pi=rate->SpecialInfo;
  215.          Einstellungen.SpeakRate=(UWORD)Div0(pi->HorizPot*360L,65535L)+(UWORD)40;
  216.          pi=vol->SpecialInfo;
  217.          Einstellungen.SpeakVolume=(UWORD)Div0(pi->HorizPot*64L,65535L);
  218.          if(female->Flags & SELECTED)
  219.            Einstellungen.SpeakSex=1;
  220.          else
  221.            Einstellungen.SpeakSex=0;
  222.          if(robot->Flags & SELECTED)
  223.            Einstellungen.SpeakMode=1;
  224.          else
  225.            Einstellungen.SpeakMode=0;
  226.          switch(gad->GadgetID)
  227.           {
  228.            case 10:
  229.              error=Translate(teststr,strlen(teststr),SpeakBuffer,1024);
  230.              if(error==0)
  231.               {
  232.                NarratorReq->rate=Einstellungen.SpeakRate;
  233.                NarratorReq->pitch=Einstellungen.SpeakPitch;
  234.                NarratorReq->mode=Einstellungen.SpeakMode;
  235.                NarratorReq->sex=Einstellungen.SpeakSex;
  236.                NarratorReq->ch_masks=&Channels;
  237.                NarratorReq->nm_masks=4;
  238.                NarratorReq->volume=Einstellungen.SpeakVolume;
  239.                NarratorReq->sampfreq=Einstellungen.SpeakFreq;
  240.                NarratorReq->message.io_Command=CMD_WRITE;
  241.                NarratorReq->message.io_Data=SpeakBuffer;
  242.                NarratorReq->message.io_Length=strlen(SpeakBuffer);
  243.                if(mwin!=NULL)
  244.                 {
  245.                  NarratorReq->mouths=1;
  246.                  io->width=0;
  247.                  io->height=0;
  248.                  io->voice.message.io_Command=CMD_READ;
  249.                  io->voice.message.io_Error=0;
  250.                  if( (SendIO(NarratorReq)) == 0)
  251.                   {
  252.                    while(io->voice.message.io_Error != ND_NoWrite)
  253.                     {
  254.                      DoIO(io);
  255.                      DrawMouth(mwin,io->width,io->height);
  256.                     }
  257.                   }
  258.                 }
  259.                else
  260.                 {
  261.                  NarratorReq->mouths=0;
  262.                  DoIO(NarratorReq);
  263.                 }
  264.               }
  265.             break;
  266.           }
  267.         break;
  268.        case CLOSEWINDOW:
  269.          ende=TRUE;
  270.         break;
  271.       }
  272.     }
  273.    if(mwin) DeleteStdWindow(mwin);
  274.    if(io) DeleteExtIO(io);
  275.    if(port) DeletePort(port);
  276.    DeleteStdWindow(win);
  277.   }
  278.  SetWindowTitles(WindowPtr,Titel,TitelText);
  279.  SetMenuStrip(WindowPtr,&Menu1);
  280. }
  281.  
  282. /* Division mit 0-Abfrage */
  283. LONG Div0(a,b)
  284.  LONG a,b;
  285. {
  286.  if(b==0) return(0);
  287.  return(a/b);
  288. }
  289.  
  290.